#include "userinfowidget.h"

UserInfoWidget::UserInfoWidget(const Message& message, QWidget *parent) :
    message(message), QDialog(parent)
{
// 1. 设置基本属性
    this->setFixedSize(400, 200);
    this->setStyleSheet("QWidget {background-color: rgb(255, 255, 255);}QLabel {font-size: 18px;}");
    this->setWindowTitle("⽤⼾详情");
    this->setWindowIcon(QIcon(":/resource/image/wechat.png"));
    // 隐藏标题栏
    // this->setWindowFlags(Qt::FramelessWindowHint);
    // 设置关闭后⾃动销毁
    this->setAttribute(Qt::WA_DeleteOnClose);
    // 设置窗⼝显⽰位置为⿏标所在位置.
    this->move(QCursor::pos());
    // 2. 设置主布局管理器
    QGridLayout* layout = new QGridLayout();
    layout->setContentsMargins(50, 30, 50, 30);
    layout->setSpacing(10);
    this->setLayout(layout);
// 3. 设置头像
    QPushButton* avatar = new QPushButton();
    avatar->setFixedSize(75, 75);
    avatar->setIconSize(QSize(75, 75));
    avatar->setIcon(message.sender.avatar);
    avatar->setStyleSheet("QPushButton { border: none; background-color:white; }");


    // 4. 设置⽤⼾序号
    QLabel* idTag = new QLabel();
    idTag->setText("序号");
    idTag->setAlignment(Qt::AlignCenter);
    idTag->setStyleSheet("QLabel { font-weight: 800; }");
    QLabel* idLabel = new QLabel();
    idLabel->setText(message.sender.userId);

    // 5. 设置昵称
    QLabel* nameTag = new QLabel();
    nameTag->setText("昵称");
    nameTag->setAlignment(Qt::AlignCenter);
    nameTag->setStyleSheet("QLabel { font-weight: 800; }");
    QLabel* nameLabel = new QLabel();
    nameLabel->setText(message.sender.nickname);
    // 6. 设置电话
    QLabel* phoneTag = new QLabel();
    phoneTag->setText("电话");
    phoneTag->setAlignment(Qt::AlignCenter);
    phoneTag->setStyleSheet("QLabel { font-weight: 800; }");
    QLabel* phoneLabel = new QLabel();
    phoneLabel->setText(message.sender.phone);

    // 7. 设置底部按钮(申请添加好友, 发送信息, 删除好友)
    QString btnStyle = "QPushButton { border: 1px solid rgb(90, 90, 90);border-radius: 5px; } QPushButton:pressed { background-color: rgb(235, 235,235);}";
    QPushButton* addFriendBtn = new QPushButton();
    addFriendBtn->setStyleSheet(btnStyle);
    addFriendBtn->setFixedSize(80, 30);
    addFriendBtn->setText("申请好友");

    QPushButton* sendMessageBtn = new QPushButton();
    sendMessageBtn->setText("发送消息");
    sendMessageBtn->setFixedSize(80, 30);
    sendMessageBtn->setStyleSheet(btnStyle);

    QPushButton* deleteFriendBtn = new QPushButton();
    deleteFriendBtn->setText("删除好友");
    deleteFriendBtn->setFixedSize(80, 30);
    deleteFriendBtn->setStyleSheet(btnStyle);

    // 8. 添加到布局管理器中
    layout->addWidget(avatar, 0, 0, 3, 2);
    layout->addWidget(idTag, 0, 2, 1, 2);
    layout->addWidget(idLabel, 0, 4, 1, 2);
    layout->addWidget(nameTag, 1, 2, 1, 2);
    layout->addWidget(nameLabel, 1, 4, 1, 2);
    layout->addWidget(phoneTag, 2, 2, 1, 2);
    layout->addWidget(phoneLabel, 2, 4, 1, 3);
    layout->addWidget(addFriendBtn, 3, 0, 1, 2);
    layout->addWidget(sendMessageBtn, 3, 2, 1, 2);
    layout->addWidget(deleteFriendBtn, 3, 4, 1, 2);

}
